<!--
 * @Author: Li Zengkun
 * @Date: 2022-09-28 17:21:33
 * @LastEditors: Li Zengkun
 * @LastEditTime: 2022-09-28 17:37:38
 * @Description: 
-->
<template>
  <div>
    <el-card shadow="hover">
      <template #header> 用户列表 </template>
      <el-table
        :data="adminList"
        style="width: 100%"
        highlight-current-row
        stripe
      >
      <el-table-column label="#" width="80" prop="id"></el-table-column>
        <el-table-column label="头像" width="100">
          <template #default="scope">
              <el-avatar :src="scope.row.avatar" :size="60"></el-avatar>
          </template>
        </el-table-column>
        <el-table-column prop="username" label="账号" width="180" sortable />
        <el-table-column prop="fullname" label="姓名" width="180" sortable />
        <el-table-column prop="sex" label="性别" width="180" sortable />
        <el-table-column prop="tel" label="手机" width="180" sortable />
        <el-table-column label="角色" width="180" sortable >
            <template #default="scope">
                <el-tag>{{scope.row.role_name}}</el-tag>
            </template>
        </el-table-column>
        <el-table-column
          prop=""
          label="上次登录"
          sortable
        />
        <el-table-column
          prop=""
          label="登录次数"
          sortable
        />
        <el-table-column label="操作">
          <template #default="scope">
            <el-button type="primary" @click="handleEdit(scope.row)"
              >编辑</el-button
            >
            <el-button type="danger" @click="handleRemove(scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <br />
      <div class="demo-pagination-block">
        <el-pagination
          background
          v-model:currentPage="params.pageIndex"
          v-model:page-size="params.pageSize"
          :page-sizes="[4, 5, 6, 7, 8, 9, 10]"
          layout=" prev, pager, next, jumper,sizes,total"
          :total="total"
          @size-change="updateList"
          @current-change="updateList"
        />
      </div>
    </el-card>
  </div>
</template>
 
<script setup>
import { ref, reactive } from "vue";
import { admin } from "@/api";

const params = ref({
  pageSize: 5,
  pageIndex: 1,
});
const initRes = await admin.getList(params.value);

const adminList = ref(initRes.data);
const total = initRes.total;
console.log(adminList.value);
console.log(initRes);

const updateList =async () => {
  const { data } = await admin.getList(params.value);
  adminList.value = data;
};
</script>

<style lang='less' scoped>
.admin-box {
  display: flex;
  align-items: center;
  .text {
    padding-left: 20px;
  }
}
.demo-pagination-block + .demo-pagination-block {
  margin-top: 10px;
}
.demo-pagination-block .demonstration {
  margin-bottom: 16px;
}
</style>
